Ask any question or analysis, as you would do with an assistant
async function makeFetchRequest(url: string, options: any) {
const response = await fetch(url, options);
return response.json();
}
async function pollForResult(resultUrl: string, headers: any) {
while (true) {
console.log("Polling for results...");
const pollResponse = await makeFetchRequest(resultUrl, { headers });
if (pollResponse.status === "done") {
console.log("- Transcription done: \n");
const audioToLlmResults = pollResponse.result.audio_to_llm;
console.log(audioToLlmResults);
break;
} else {
console.log("Transcription status : ", pollResponse.status);
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}
}
async function startTranscription() {
const gladiaKey = "YOUR_GLADIA_API_KEY";
const requestData = {
audio_url: "YOUR_AUDIO_URL",
audio_to_llm: true,
audio_to_llm_config: {
prompts: [
"Extract the key points from the transcription as bullet points",
"Generate a title from this transcription",
],
},
};
const gladiaUrl = "https://api.gladia.io/v2/pre-recorded/";
const headers = {
"x-gladia-key": gladiaKey,
"Content-Type": "application/json",
};
console.log("- Sending initial request to Gladia API...");
const initialResponse = await makeFetchRequest(gladiaUrl, {
method: "POST",
headers,
body: JSON.stringify(requestData),
});
console.log("Initial response with Transcription ID :", initialResponse);
if (initialResponse.result_url) {
await pollForResult(initialResponse.result_url, headers);
}
}
startTranscription();
{
"success": true,
"is_empty": false,
"results": [
{
"success": true,
"is_empty": false,
"results": {
"prompt": "Extract the key points from the transcription as bullet points",
"response": "The main entities key points from the transcription are:\n- ..."
},
"exec_time": 1.7726809978485107,
"error": null
},
{
"success": true,
"is_empty": false,
"results": {
"prompt": "Generate a title from this transcription",
"response": "The Great Title"
},
"exec_time": 1.7832809978258485,
"error": null
}
],
"exec_time": 6.127103805541992,
"error": null
}
results
key.Was this page helpful?